11111
2463
 
特别是两件事可能需要注意:
全局声明const RecaptchaItem = React.createClass({..}),不要在render()中使其成为局部变量
必须同时提供onloadCallback和verifyCallback,如果缺少onloadCallback,则reCAPTCHA将不会触发调用verifyCallback,并且Form无法获取该值。这可能是react-recaptcha的错误
这是正确的代码:
const {Form,Icon,Input,Button,Checkbox} = antd;
const FormItem = Form.Item;
const RecaptchaItem = React.createClass({
verifyCallback(result){
console.log('verifyCallback',结果);
this.props.onChange(result); //验证后通知表单
},
render(){
返回( {}}
verifyCallback = {this.verifyCallback}
/>);
}
});
const NormalLoginForm = Form.create()(React.createClass({
handleSubmit(e){
e.preventDefault();
this.props.form.validateFields((err,values)=> {
如果(!err){
console.log('接收的值的形式:',值);
}
});
},
render(){
const {getFieldDecorator} = this.props.form;
返回(
{getFieldDecorator('userName',{ 规则:[{必填:是,消息:“请输入您的用户名!” }], })( } placeholder =“ Username” /> )} {getFieldDecorator('password',{ 规则:[{必填:是,消息:“请输入密码!” }], })( } type =“ password”占位符=“ Password” /> )} {getFieldDecorator('captcha',{ 规则:[{必填项:是,消息:“请输入您获得的验证码!” }], })()} {getFieldDecorator('remember',{ valuePropName:“已选中”, initialValue:true, })( 记住我 )} 忘记密码